import { videoApi } from '@/api'
import * as TYPE from '@/store/actionType/videoType'

const state = {
	video: {},
	videoDetail: {
    mime: "video/mp4",
    cover: "/static/images/author.jpg",
    url: "https://cdn.theguardian.tv/webM/2015/07/20/150716YesMen_synd_768k_vp8.webm",
  },
	videoList: [],
}

const getters = {
	videoDetail: state => state.videoDetail,
	videoList: state => state.videoList,
	video: state => state.video,
}

const actions = {
	videoList({commit, state, rootState}) {
		rootState.requesting = true
		commit(TYPE.VIDEO_LIST_REQUEST)
		videoApi.videoList().then((response) => {
			rootState.requesting = false
      console.log('aaaaaaaaaa', response)
			commit(TYPE.VIDEO_LIST_SUCCESS, response)
		}, (error) => {
			rootState.requesting = false
			commit(TYPE.VIDEO_LIST_FAILURE)
		})
	},
	videoDetail({commit, state, rootState}, param) {
    console.log('commit, state, rootState', commit, state, rootState)
		rootState.requesting = true
		commit(TYPE.VIDEO_DETAIL_REQUEST)
		videoApi.videoDetail(param).then((response) => {
			rootState.requesting = false
      console.log('bbbbbbbb', response)

			commit(TYPE.VIDEO_DETAIL_SUCCESS, response)
		}, (error) => {
			rootState.requesting = false
			commit(TYPE.VIDEO_DETAIL_FAILURE)
		})
	},
}

const mutations = {
	[TYPE.VIDEO_LIST_REQUEST] (state) {

	},
	[TYPE.VIDEO_LIST_SUCCESS] (state, response) {
		state.video = response
		state.videoList = response.data
 	},
	[TYPE.VIDEO_LIST_FAILURE] (state) {

	},
  [TYPE.VIDEO_DETAIL_REQUEST] (state) {

	},
	[TYPE.VIDEO_DETAIL_SUCCESS] (state, response) {
		state.videoDetail = response.data
 	},
	[TYPE.VIDEO_DETAIL_FAILURE] (state) {

	}
}

export default {
	state,
	getters,
	actions,
	mutations
}
